package Chapter04.TS;

import java.util.*;

public class CelebrityRanking {



    private Map<String, Integer> celebrityMap;

    public CelebrityRanking() {
        celebrityMap = new HashMap<String, Integer>();
    }

    public void addCelebrity(String name, int popularity) {
        celebrityMap.put(name, popularity);
    }

    public void removeCelebrity(String name) {
        celebrityMap.remove(name);
    }

    public void displayRanking() {
        List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>(celebrityMap.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o2.getValue().compareTo(o1.getValue());
            }
        });
        System.out.println("Celebrity Ranking:");
        for (Map.Entry<String, Integer> entry : list) {
            System.out.println(entry.getKey() + " - " + entry.getValue());
        }
    }

    public static void main(String[] args) {
        CelebrityRanking ranking = new CelebrityRanking();
        ranking.addCelebrity("Taylor Swift", 100);
        ranking.addCelebrity("Justin Bieber", 90);
        ranking.addCelebrity("Beyonce", 80);
        ranking.addCelebrity("Adele", 70);
        ranking.addCelebrity("Ed Sheeran", 60);
        ranking.displayRanking();
    }
}